import { fileURLToPath, URL } from 'node:url'
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite' // 自动引入插件
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({
      imports: ['vue', 'vue-router'],
      dts: 'src/auto-import.d.ts'
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    }
  },
  build: {
    chunkSizeWarningLimit: 2000,
    cssCodeSplit: true, // css 拆分
    sourcemap: false,
    minify: 'esbuild', // 是否禁用最小化混淆， esbuild打包速度最快 terser打包体积最小
    assetsInlineLimit: 4000 // 小于这个值的东西会转成base64
  },
  server: {
    proxy: {
      "/api/omc": {
        target: "http://192.168.6.90:29107/omc",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/omc/, ""),
      },
      "/api/emc": {
        target: "http://192.168.6.90:29097/emc",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/emc/, ""),
      },
      "/api/tmc": {
        target: "http://192.168.6.90:28094/api/tmc",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/tmc/, ""),
      },
    },
  },
})
